package com.paradogs.framework.utils;

import com.paradogs.framework.server.ByteMessage;
import com.paradogs.framework.server.ParadogsContext;
import io.netty.channel.Channel;

/**
 * @author: yumi
 * @date: 2023/12/26  13:07
 * @Description: 消息上下文工具
 */
public class ContextUtils {

    private static ThreadLocal<ParadogsContext> context = new ThreadLocal<>();

    /** 获得上下文 */
    public static ParadogsContext getContext() {
        return context.get();
    }

    /** 设置上下文 */
    public static void setContext(ParadogsContext ctx) {
        ContextUtils.context.remove();
        ContextUtils.context.set(ctx);
    }

    public static Channel getChannel() {
        return getContext().getChannel();
    }


    public static ByteMessage getMessage() { // ByteMessage
        return getContext().getMessage();
    }

    /** 清空上下文 */
    public static void release() {
        context.remove();
    }

}
